package org.gd.hellospring;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class SimpleAspect {

    @Before("execution(* SpringDao.getName())")
    public void printBefore(JoinPoint joinPoint) {
        System.out.println("printBefore: " + joinPoint.getThis());
    }

    @After("execution(* SpringDao.getName())")
    public void printAfter(JoinPoint joinPoint) {
        System.out.println("printBefore: " + joinPoint.getThis());
    }

    @AfterThrowing(
            value = "execution(* SpringDao.throwIt())",
            throwing = "e")
    public void throwHandle(Throwable e) {
        synchronized (System.out) {
            System.out.println("==========================");
            e.printStackTrace(System.out);
            System.out.println("==========================");
        }
    }
}
